package com.finddreams.module_home;

import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.finddreams.module_base.base.BaseFragment;
import com.finddreams.module_base.event.LoginStateEvent;
import com.finddreams.module_base.utils.ModuleRouteService;
import com.finddreams.module_base.utils.RouteUtils;

@Route(path = RouteUtils.Home_Fragment_Main)
public class HomeFragment extends BaseFragment {

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.home_fragment,null);
        view.findViewById(R.id.bt_click).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (LoginStateEvent.getInstance().isSuccess()) {
                    showName();
                }else{
                    Toast.makeText(getActivity(),"未登录，跳转登录",Toast.LENGTH_SHORT).show();
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            RouteUtils.startLoginActivity();
                        }
                    },1000);
                }
            }
        });
        return view;
    }
    public void showName(){
        String useName = ModuleRouteService.getUserName();//String userName = RouteUtils.getUserName();
        Toast.makeText(getActivity(),useName,Toast.LENGTH_SHORT).show();
    }
}
